package com.xiao.springmvc.controller.product;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.xiao.springmvc.entity.ProductImage;
import com.xiao.springmvc.entity.ProductInfo;
import com.xiao.springmvc.entity.jdo.ProductGetJdo;
import com.xiao.springmvc.entity.jdo.ProductShowJdo;


public class ProductJson {

	
	public Object productGetJson(ProductInfo productInfo,ProductImage productImage){
		
		ProductGetJdo jdo = new ProductGetJdo();
		
		jdo.setProductId(productInfo.getId());
		jdo.setProductName(productInfo.getName());
		jdo.setProductIntroduce(productInfo.getIntroduce());
		jdo.setProductPicture(productImage.getFilepath());
		
		return jdo;
	}
	
	public Object productShowJson(ProductInfo product,List<ProductImage> imageList){
		ProductShowJdo jdo = new ProductShowJdo();
		
		jdo.setProductName(product.getName());
		jdo.setProductDetail(product.getDetail());
		jdo.setProductBook(product.getInstructionBook());
		jdo.setProductSize(product.getInstructionSize());
		
		Map<Integer,String> map = new HashMap<Integer,String>();
		ProductImage im = null;
		for(int i =0;i<imageList.size();i++){
			im = imageList.get(i);
			map.put(i+1, im.getFilepath());
		}
		List<Object> list =new ArrayList<Object>();
		list.add(map);
		
		jdo.setProductPicture(list);
		
		return jdo;
	}
}
